# -*- coding: utf-8 -*-
import time, sys
from django.core.management.base import BaseCommand
from enbook.games.models import Games
from enbook.games import Loader

class Command(BaseCommand):
    help = 'Updates games\' string dates to regular SQL dates'

    def handle(self, *args, **options):
        """
            Точка входа при выполнении команды
            Преобразует строковые даты игр в машиночитаемые
        """
        games = Games.objects.all().select_related('domain').filter(game_date__isnull=True)
        for game in games:
            if len(game.game_date_str)>0:
                game.game_date = Loader.str2date(game.game_date_str)
                if not game.game_date:
                    print game.__dict__
                    print 'domain', game.domain.domain_name
            game.save()